<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- namespace必须指向Dao接口 -->
<mapper namespace="net.fongtech.hotel.point.mapper.${javaEntityName}Mapper">
	
	<resultMap id="${javaEntityName}ResultMap" type="net.fongtech.test.entity.${javaEntityName}">
		${resultMap}
	</resultMap>
	
	<!-- 定义可重用的SQL代码段，可以包含在其他语句中 -->
	<sql id="base_column">
		 ${baseColumn}
	</sql>
	
	<sql id="base_value_column">
		 ${baseValueColumn}
	</sql>
	
	<!-- 定义可重用的WHERE SQL公共代码段，可以包含在其他语句中 -->
	<sql id="where_column">
		${whereColumn}
	</sql>
	
	<!-- 设置语句 -->
	<sql id="set_column">
		${setColumn}
	</sql>

	<!-- 根据ID查询 -->
	<select id="find" resultMap="${javaEntityName}ResultMap">
		SELECT	<include refid="base_column" />
		FROM	${tableName}
		WHERE ID=<#noparse>#{id,jdbcType=BIGINT}</#noparse>
	</select>
	
	<!-- 查询所有 -->
	<select id="findAll" resultMap="${javaEntityName}ResultMap">
		SELECT	<include refid="base_column" />
		FROM	${tableName}
	</select>
	
	<!-- 统计记录数 -->
	<select id="count" resultType="long">
		SELECT COUNT(*) FROM ${tableName}
		<where> 
			<include refid="where_column" />
		</where>
	</select>
	
	<!-- 插入 -->
	<insert id="insert" parameterType="net.fongtech.test.entity.${javaEntityName}">
		<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="id">  
	          SELECT LAST_INSERT_ID() AS ID    
	    </selectKey>  
		INSERT  ${tableName} 
				(<include refid="base_column" /> )
		VALUES	(<include refid="base_value_column" />)
	</insert>
	
	<!-- 修改 -->
	<update id="update" parameterType="net.fongtech.test.entity.${javaEntityName}">
		UPDATE	 ${tableName}
		<set>
			<include refid="set_column" />
		</set>
		WHERE ID=<#noparse>#{id,jdbcType=BIGINT}</#noparse>
	</update>
	
	<!-- 删除单条记录 -->
	<delete id="delete">
		DELETE	FROM  ${tableName}
		WHERE ID=<#noparse>#{id,jdbcType=BIGINT}</#noparse>
	</delete>
	
	<!-- 删除多条记录-->
	<delete id="deleteAll">
		DELETE	FROM  ${tableName}
		WHERE	ID	IN
    	<foreach item="${javaEntityName}Id" index="index" collection="ids" open="(" separator="," close=")">
	  		<#noparse>#{</#noparse>${javaEntityName}Id<#noparse>} </#noparse>
		</foreach>
	</delete>
	
	<!-- 根据参数查询列表-->
	<select id="findByParams" resultMap="${javaEntityName}ResultMap">
		SELECT	<include refid="base_column" />
		FROM 	 ${tableName}
		<where> 1=1
			<include refid="where_column" />
		</where>
	</select>
	
	<!-- 分页查询-->
	<select id="findByPage" resultMap="${javaEntityName}ResultMap">
		SELECT
		<include refid="base_column" />
		FROM  ${tableName}
		<where> 1=1
			<include refid="where_column" />
		</where>
	</select>
	
</mapper> 